<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>My JSP 'updateMailExpress.jsp' starting page</title>
		
	</head>
	<body>
<section class="content">
	<div class="row">
		<div class="col-md-12">
		<div class="box box-solid box-primary">
					<div class="box-header">
						<h3 class="box-title">${titlePage}</h3>
					</div>
					<div class="box-body">
		<div class="alert alert-success" id="message" style="display: none;">
			<button data-dismiss="alert" class="close">
				×
			</button>
			<span id="content">修改成功</span>
		</div>
		<fieldset>
		<div class="form-group row">
			<div class="col-sm-3">
				<div class="input-group col-md-12">
					<label for="pmsprinters_corpLevel" class="input-group-text">
						电子面单名称:
					</label>
					<input type="text" id="expressStyleName" name="styleName"
							class="form-control input-large required" minlength="3" value="${expressStyle.styleName}"/>
						<span id="styleNameMessage"></span>
				</div>
			</div>
			
			<div class="col-sm-3">
				<div class="input-group col-md-12">
					<label for="pmsprinters_corpLevel" class="input-group-text">
						@宽度
					</label>
					<input class="form-control" id="expressWidth" type="text" >
				</div>
			</div>
			<div class="col-sm-3">
				<div class="input-group col-md-12">
					<label for="pmsprinters_corpLevel" class="input-group-text">
						@高度
					</label>
					<input class="form-control" id="expressHeight" type="text" >
				</div>
			</div>
			
			<font color="red">精确到两位小数</font>
			</div>
			
			
			<div class="form-group row">
			<div class="col-sm-12">
				<div class="input-group col-md-12">
					<textarea rows="20" cols="20" style="width: 1000px;height: 500px;" class="form-control" id="styleContent" value="${expressStyle.styleContent}"></textarea>
				</div>
			</div>
			
			</div>
		</fieldset>
		
		<div class="modal-footer bg-gray">
			<input id="button_btn" class="btn btn-primary" type="button" value="更新" onclick="updateAjaxMailExpressStyle()"/>
			<input id="cancel_btn" class="btn" type="button" value="返回" onclick="history.back()" />
		</div>
</div>
</div>
</div>
</div>
</section>

		<script type="text/javascript">
		var width;
		var height;
		function valNumber(tempNumber){
		  var rex_one="^[0-9]+(.[0-9]{0,2})?$";
		  var result_one =tempNumber.match(rex_one);
		  if(result_one==null){
		    return false;
		  }
	   	   return true;
		}
		
		function widthHeight() {
			var tempWidth = "${expressStyle.remarks}";
			var tempString = tempWidth.split("*");
			for ( var i = 0; i < tempString.length; i++) {
				if (i == 0) {
					var width = tempString[i];
				
					width=width/100;
					$("#expressWidth").val(width);
				} else if (i == 1) {
					var height = tempString[i];
					height=height/100;
					$("#expressHeight").val(height);
				}
			}
			
		}
		widthHeight();
	function updateAjaxMailExpressStyle() {
		var expressWidth=$("#expressWidth").val();
		var expressHeight=$("#expressHeight").val();
		
		if(!valNumber(expressWidth)){
		   alert("请填入正确的长度");
		   $("#expressWidth").focus();
		   //return;
		}else{
		 expressWidth=expressWidth*100;
		}
		if(!valNumber(expressHeight)){
		   alert("请填入正确的宽度");
		   $("#expressHeight").focus();
		   //return;
		}else{
		   expressHeight=expressHeight*100;
		}
		var expressStyleName = $( "#expressStyleName").val();
        if (expressStyleName == "") {$("#styleNameMessage").html( "<font color=\"red\">请填写模版名称</font>");
	    $(function() {
		setTimeout(function() {$("#styleNameMessage").hide();}, 6000);
	});
	return;
    }
		$.ajax({
			type : 'post',
			url : '${ctx}/v2/expressPrinting/updateAjaxMailExpressStyle',
			data : {
				content:encodeURI($("#styleContent").val()),
				type:'mail',
				expressWidth:expressWidth,
				expressHeight:expressHeight,
				expressStyleName:expressStyleName,
				id:'${expressStyle.id}'
			},
			dataType : 'json',
			success : function(data) {
				
				    $("#content").html(data.content);
					$("#message").show();
					$(function() {
						setTimeout(function() {
							$("#message").hide();
						}, 6000);
					});
				
			},
			error : function() {

			}
		});
	}
	
	function getAjaxExpress() {
	      
			$.ajax({
				type : 'post',
				url : '${ctx}/v2/expressPrinting/getAjaxExpress',
				data : 'expressStylesId=${expressStyle.id}' ,
				dataType : 'json',
				success : function(data) {
					if (data.status == "1") {
						$("#styleContent").val(data.content.styleContent);
					}  else if (data.status == "0") {
						alert("获取运单号正则表达式错误！");
					}
				},

				error : function() {

				}
			});
		}
	getAjaxExpress();
</script>
	</body>
</html>
